﻿using System;
using System.Collections.Generic;
using DMS.Business.Utility;
using DMS.Business.Modules.Organization;

namespace DMS.Web.Modules.SystemManagement.Organization
{
    public partial class UserRoleSetting : System.Web.UI.Page
    {
        private string _ActorID = "";
        private ActorTypes _ActorType = ActorTypes.User;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.GetParams();

            if (!IsPostBack)
            {
                if (this._ActorType == ActorTypes.User)
                {
                    User user = UserHelper.GetUserByID(this._ActorID);
                    this.lblSettingActor.Text = (user == null) ? string.Empty : user.Name;
                }
                List<Role> roles = UserHelper.GetActorRole(this._ActorID);
                roleList.DataSource = roles;
                roleList.DataBind();
            }
        }

        private void GetParams()
        {
            if (!string.IsNullOrEmpty(this.Request["ActorID"]))
            {
                try
                {
                    this._ActorID = this.Request["ActorID"].ToString();
                }
                catch(Exception ex)
                {
                    LogHelper.LogException(ex);
                }
            }

            if (!string.IsNullOrEmpty(this.Request["ActorType"]))
            {
                this._ActorType = (ActorTypes)Enum.Parse(typeof(ActorTypes), this.Request["ActorType"]);
            }
        }
    }
}